﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using LightPersist.Storage;
using TestDomainModel;

namespace PerformanceTests
{
	class Program
	{
		static void Main()
		{
			var sw = Stopwatch.StartNew();
#if P
			P.Check["all"] = () =>{ 
#endif
				using (var storage = new InmemoryStorage("test"))
				{
					using (var context = new LightPersist.LightPersistContext(storage, TestDomainModelMetainfo.Metainfo))
					{
						using (var tr = context.BeginTransaction())
						{
							var currentChild = context.RootClass<FakeControl>();
							for (int i = 0; i < 1000; i++)
							{
								FakeControl newChild = null;
#if P
								P.Check["create"] = () =>
								{
#endif
									newChild = context.Create<FakeControl>(); 
#if P
								};
								P.Check["insert"] = () =>
								{
#endif
									currentChild.Children.Add(newChild);
#if P
								};
#endif
								currentChild = newChild;
							}
#if P
							P.Check["Commit"] = () =>
							{
#endif
								tr.CommitTransaction();
#if P
							};
#endif
						}
					}
				}
#if P
			};
			Console.WriteLine(P.Result);
#endif
			Console.WriteLine(sw.ElapsedMilliseconds);
		}
	}
}
